<?php
/**
 * Created by PhpStorm.
 * User: ewen
 * Date: 2020-01-02
 * Time: 10:49
 */

namespace app\common\validate;


use think\Validate;

class Admin extends Validate
{
    /**
     * 验证规则
     * @var array
     */
    protected $rule = [
        //  管理员姓名
        'adminName' => 'require',
//        // 验证字段值是否唯一
        'checkAdminName' => 'unique:admin,adminName',
        //  管理员密码
        'adminPwd' => 'require|max:15|min:6',
        'adminPwdEdit' => 'max:15|min:6',
        //  旧密码
        'oldPwd' => 'require',
        //  新密码
        'newPwd' => 'require|max:15|min:6',
        //  重复新密码
        'reNewPwd' => 'require|max:15|min:6|confirm:newPwd',
        //  角色ID
        'roleID' => 'require|number|gt:0',
        //  管理员ID
        'adminID' => 'require|number|gt:0',

    ];

    /**
     * 验证信息
     * @var array
     */
    protected $message = [
        'adminName.require' => '{%admin name can not be empty}',

        'checkAdminName.unique' => '{%admin name already exist}',

        'adminPwd.require' => '{%admin password can not be empty}',
        'adminPwd.max' => '{%admin password too long}',
        'adminPwd.min' => '{%admin password too short}',
        'adminPwdEdit.max' => '{%admin password too long}',
        'adminPwdEdit.min' => '{%admin password too short}',

        'oldPwd.require' => '{%old password can not be empty}',

        'newPwd.require' => '{%new password can not be empty}',
        'newPwd.max' => '{%new password too long}',
        'newPwd.min' => '{%new password too short}',

        'reNewPwd.require' => '{%repeat password can not be empty}',
        'reNewPwd.max' => '{%repeat password too long}',
        'reNewPwd.min' => '{%repeat password too long}',
        'reNewPwd.confirm' => '{%not same password}',

        'roleID.require' => '{%invalid role id}',
        'roleID.number' => '{%role id must be a number}',
        'roleID.gt' => '{%please choose a role}',

        'adminID.require' => '{%admin id can not be empty}',
        'adminID.number' => '{%admin id must be a number}',
        'adminID.gt' => '{%invalid admin id}',
    ];

    /**
     * 验证场景
     * @var array
     */
    protected $scene = [
        //  管理员登录
        'login' => ['adminName', 'adminPwd'],
        //  管理员修改密码
        'changePwd' => ['oldPwd', 'newPwd', 'reNewPwd'],
        //  添加管理员
        'addAdmin' => ['adminName', 'adminPwd', 'roleID', 'checkAdminName'],
        //  编辑管理员
        'editAdmin' => ['adminName', 'adminPwdEdit', 'roleID', 'checkAdminName', 'adminID']
    ];

}